﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            d();

        }
        static void a()
        {
            //            用户输入正方形边长，用* 打印出实心正方形。

            //如：用户输入5，则输出如下图形。
            //*****
            //*****
            //*****
            //*****
            //*****
            Console.WriteLine("用户输入正方形边长:");
            int a = int.Parse(Console.ReadLine());
            string[,] arr = new string[a, a];


            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    arr[i, j] = "*" + " ";
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }

        }
        static void b()
        {
            Console.WriteLine("九九乘法表");
            string[,] arr = new string[9, 9];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    arr[i, j] = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1) + "\t";
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine(" ");

            }
        }
        static void c()
        {
            //            用户输入正方形边长，用* 打印出空心正方形。

            //如：用户输入5，则输出如下图形。
            //*****
            //*   *
            //*   *
            //*   *
            //*****
            Console.WriteLine(" 用户输入正方形边长，用* 打印出空心正方形:");
            int a = int.Parse(Console.ReadLine());
            string[,] arr = new string[a, a];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (i >= 1 && i <= a - 2 && j >= 1 && j <= a - 2)
                    {
                        arr[i, j] = " " + " ";
                    }
                    else
                    {
                        arr[i, j] = "*" + " ";
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
        }
        static void d()
        {
            //  *
            // ***
            //*****
            // ***
            //  *
            int x = 5, y = (x - 1) / 2;
            string[,] arr = new string[x, x];
            for (int i = 0; i <= y; i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (j >= y - i && j <= y + i)
                    {
                        arr[i, j] = "* ";
                    }
                    else
                    {
                        arr[i, j] = "  ";
                    }
                }
            }
            for (int i = (x - 1); i > y; i--)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (j >= i - y && j < x + y - i)
                    {
                        arr[i, j] = "* ";
                    }
                    else
                    {
                        arr[i, j] = "  ";
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
        }
        
        static void e()
        {//杨辉三角
            int[][] arr = new int[10][];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                arr[i] = new int[i + 1];
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (i == 0 || j == 0)
                    {
                        arr[i][j] = 1;
                    }
                    else
                    {
                        //arr[i, j] =Convert.ToString(int.Parse(arr[i - 1, j]) + int.Parse(arr[i - 1, j - 1]));
                        if ((i == 2 && j == 2) || i == j)
                        {
                            arr[i][j] = 1;
                        }
                        else
                        {
                            arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
                        }
                    }
                }
            }

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                foreach (int item in arr[i])
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
            }


        }
        //数组练习1
        static void g()
        {
            int[] arr = { 1, 2, 4, 5, 6 };
            Console.Write("数组中下标是偶数的元素有：");
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                if (i % 2 == 0)
                {
                    Console.Write(arr[i] + " ");
                }

            }
        }
        //数组练习2
        static void f()
        {
            //如果一个数组保存元素是有序的（从大到小），
            //向这个数组中插入一个数，
            //使得插入后的数组元素仍然保持有序。
            int[] arr = { 10, 7, 4, 3 };
            int[] arr1 = new int[5];
            int temp = 0;
            Console.WriteLine("插入前的数组：");
            foreach (int item in arr)
            {
                Console.Write(item + " ");
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                arr1[i] = arr[i];
            }

            Console.WriteLine();
            Console.WriteLine("请输入一个数：");
            arr1[4] = int.Parse(Console.ReadLine());
            Console.WriteLine("插入后的数组：");
            foreach (int item in arr1)
            {
                Console.Write(item + " ");
            }
            for (int i = 0; i < arr1.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < arr1.GetLength(0) - 1 - i; j++)
                {
                    if (arr1[j] < arr1[j + 1])
                    {
                        temp = arr1[j];
                        arr1[j] = arr1[j + 1];
                        arr1[j + 1] = temp;

                    }
                }
            }
            Console.WriteLine("插入后的数组：");
            foreach (int item in arr1)
            {
                Console.Write(item + " ");
            }
        }
    }
}
